﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using myschoolDal;

namespace school
{
    public partial class mandelectmaninformation : Form
    {
        private string name;
        private long id;

        public mandelectmaninformation()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //name = textBox2.Text.ToString();
            //id = Convert.ToInt64(textBox3.Text.Trim());
            if (textBox2.Text == "" && textBox3.Text == "")
            {
                MessageBox.Show("错误：" + bug.Class1.worng4001, "提示");
            }
            else if (textBox2.Text != "" && textBox3.Text != "")
            {
                name = textBox2.Text.ToString();
                id = Convert.ToInt64(textBox3.Text);
                if (manserver.CheckId(id))
                {
                    if (manserver.GetManInformationName(id) != name)
                    {
                        textBox2.Text = manserver.GetManInformationName(id);
                    }
                }
                else
                {
                    MessageBox.Show("错误：" + bug.Class1.wrong5002, "提示");
                }
            }
            else if (textBox2.Text != "" && textBox3.Text == "")
            {
                MessageBox.Show("错误：" + bug.Class1.worng4001, "提示");
            }
            else if (textBox2.Text == "" && textBox3.Text != "")
            {
                id = Convert.ToInt64(textBox3.Text);
                if (manserver.CheckId(id))
                {
                    name = manserver.GetManInformationName(id);
                    textBox2.Text = name;
                }
                else
                {
                    MessageBox.Show("错误：" + bug.Class1.wrong5002, "提示");
                }
            }
            dataGridView1.DataSource = manserver.GetManInformation(id).Tables[0].DefaultView;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox3.Text != "")
            {
                manserver.DeleteManInformation(id);
            }
        }
    }
}
